#coding=utf-8

import AsmPanic

class Register():
    
    __type = "T";
    
    __numero = -1;
    
    __value = -1;
    
    __isReading = False;
    
    __isWriting = False;
    
    __isInitialized = False;
    
    def __init__(self, type, num, value = -1):
        self.__type = type;
        self.__numero = num;
        if(value >= 0):
            self.__value = value;
            self.__isInitialized = True;
        else:
            self.__value = -1;
            self.__isInitialized = False;
        
    def isReading(self):
        return self.__isReading;
    
    def isWriting(self):
        return self.__isWriting;
    
    def isInitialized(self):
        return self.__isInitialized;
    
    def setReading(self):
        self.__isReading = True;
        self.__isWriting = False;
        
    def setWriting(self):
        self.__isWriting = True;
        self.__isReading = True;
    
    def getNumero(self):
        return self.__numero;
    
    def getType(self):
        return self.__type;
    
    def getValue(self):
        if(self.isReading()):
            return self.__value;
    
    def getRegister(self):
        return "$" + self.getType() + str(self.getNumero()) 
    
    def setValue(self, val):
        if(self.isWriting()):
            self.__value = val;
        else:
            raise AsmPanic("Registrador tentando ser escrito sem estar habilitado para escrita");